package manage.controller;
import com.alibaba.fastjson.JSONObject;
import manage.base.BaseController;
import manage.model.Bianzhi;
import manage.service.BianzhiServcie;
import manage.service.impl.BianzhiServcieImpl;
import manage.util.Msg;
import manage.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
/**
 * @author: create by  Raphaelkxy
 * @version: v1.0
 * @description: manage.controller
 * @date:2019/8/26
 */
@Controller
public class BianzhiController extends BaseController {

    @Autowired
    private BianzhiServcie bianzhiServcie;

    /**
     * 获取单个编制
     */
    @RequestMapping(value = "/getbianzhibyid",produces = "text/html;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String getBianZhi(@RequestBody Integer id){
        Bianzhi bianzhi = bianzhiServcie.geyByid(id);
        String returninfo = JSONObject.toJSONString(bianzhi);
        return returninfo;
    }
    /**
     * 获取列表
     */
    @ResponseBody
    @RequestMapping(value = "/getBianZhiData",produces = "text/html;charset=UTF-8", method = RequestMethod.GET)
    public String getBianzhiData(HttpServletRequest request){
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        List<Bianzhi>list= bianzhiServcie.getBianzhiList();
        validate(page);
        HashMap result = new HashMap();
        result.put("arrayList", list);
        result.put("pageInfo", page);
        String returnInfo = JSONObject.toJSONString(result);
        return returnInfo;
    }
    /**
     * 根据删除
     */
    @ResponseBody
    @RequestMapping(value = "deletebianhi",produces = "text/html;charset=UTF-8",method = RequestMethod.DELETE)
    public String deleteBianzhi(@RequestBody Integer id){
        int i = bianzhiServcie.deleteBianzhi(id);
        if(i>0){
            String returnInfo = JSONObject.toJSONString("success");
            return returnInfo;
        }else {
            String returnInfo = JSONObject.toJSONString("fail");
            return returnInfo;
        }
    }
    /**
     * 根据提交更新
     */
    @ResponseBody
    @RequestMapping(value = "updatebianzhi",method = RequestMethod.PUT)
    public String updateBianzhi(@RequestBody  Bianzhi bianzhi){
        int i = bianzhiServcie.updateBianzhi(bianzhi);
        if(i>0){
            String returnInfo1 = JSONObject.toJSONString("success");
            return returnInfo1;
        }else {
            String returnInfo1 = JSONObject.toJSONString("fail");
            return returnInfo1;
        }
    }
    /**
     * 根据新添加
     */
    @ResponseBody
    @RequestMapping(value = "insetdata",method = RequestMethod.POST)
    public String addBianzhoData(Bianzhi bianzhi){
        int i = bianzhiServcie.insertBianzhi(bianzhi);
        if (i > 0)
            return "添加成功";
        else
            return "添加失败";
    }
}
